package com.taotao.search.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.surefire.shade.org.apache.maven.shared.utils.io.IOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.common.pojo.Item;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.JsonUtils;
import com.taotao.search.service.ISyncSolrService;

@Controller
@RequestMapping("/search/sync")
public class SyncSolrController {
	@Autowired
	private ISyncSolrService syncSolrService;

	/**
	 * 将商品基本信息同步到索引库
	 * 
	 * @param ItemInfo
	 * @throws IOException
	 */
	@RequestMapping(value = "/item/info")
	public TaotaoResult SyncItemBaseInfo(HttpServletRequest request)
			throws IOException {
		ServletInputStream inputStream = request.getInputStream();
		String jsonStr = IOUtil.toString(inputStream);
		Item item = JsonUtils.jsonToPojo(jsonStr, Item.class);
		TaotaoResult taotaoResult = this.syncSolrService
				.SyncSolrItemBaseInfo(item);
		if (200 != taotaoResult.getStatus()) {
			return null;
		}
		return taotaoResult;
	}
}
